package com.caichen.scheduler.task;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.caichen.scheduler.pojo.Order;
import com.caichen.scheduler.service.OrderService;
import com.caichen.utils.tools.DateUtils;

public class UpdateOrderClosedTask {

	
	private static Logger logger = LoggerFactory.getLogger(UpdateOrderClosedTask.class);
	
	@Autowired
	private OrderService orderService;
	
	
	public void run() {
		logger.info("========================================清楚超过1小时未支付的订单任务开始=================================================");
		String dateTime = DateFormatUtils.format(new Date(), DateUtils.dateFormat_default);
		logger.info("==================================分销时间节点：" + dateTime + "========================================");
		List<Order> list = orderService.getOverTimeOrderPay();
		if (list == null) list = new ArrayList<>();
		for (Order order : list) {
			try {
				orderService.updateOverTimeOrderPay(order);
			} catch (Exception e) {
				logger.error("Error 处理订单超时1小时发生异常：orderId=" + order.getOrderId(), e);
			}
		}
		logger.info("========================================清楚超时1小时未支付订单任务完成（"+ list.size() +"）=================================================");
	}
}
